package rsb21411ls.d1123;


import java.util.Comparator;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

public class Demo04 {
    //Tree set 中添加自定义对象
    public static void main(String[] args) {
        rsb21411ls.d1123.Student s1=new rsb21411ls.d1123.Student("ligui",56);
        rsb21411ls.d1123.Student s2=new rsb21411ls.d1123.Student("liui",57);
        rsb21411ls.d1123.Student s3=new rsb21411ls.d1123.Student("i",58);
        rsb21411ls.d1123.Student s4=new rsb21411ls.d1123.Student("idddd",80);
        //Set <Student>  studentSet=new TreeSet<>();
        TreeSet<Student> studentSet=new TreeSet<>(new Comparator<Student>() {//重写tree Set方法
            @Override
            public int compare(Student o1, Student o2) {
                return Double.compare(o1.getScore(),o2.getScore());
            }
        });


        studentSet.add(s1);
        studentSet.add(s2);
        studentSet.add(s3);
        System.out.println(studentSet);
        System.out.println(studentSet.first());//最高分
        System.out.println(studentSet.last());//最低分
        //System.out.println(studentSet,57);//小于60的
        SortedSet<Student> stud= studentSet.subSet(new Student("aa",57),new Student("ss",80));
        System.out.println("545!!!"+stud);//输出57 到80 之间的学生
        stud.forEach(student -> System.out.println("forEach输出"+studentSet));
        //stream 流
    }
}
